package com.jz.digital.base

import android.view.View
import com.jz.digital.R
import kotlin.math.abs

/**
 * @author jiangdz
 * @date 2021/9/11
 * @time 10:14
 * 用途:带点击事件的Activity
 */
abstract class BaseClickActivity<P : BasePresenter<*>> : BaseActivity<P>(), View.OnClickListener {

    override fun onClick(v: View) {
        if (!canClick(v)) {
            println("500毫秒之内只能触发一次点击。")
            return
        }
        clickAction(v)
    }

    abstract fun clickAction(view: View)
    private fun canClick(view:View?):Boolean{
        val currentTimeStamp=System.currentTimeMillis()
        if (view==null||view.getTag(R.id.tag_click) !is Long){
            view?.setTag(R.id.tag_click,currentTimeStamp)
            return true
        }
        if (abs(currentTimeStamp-view.getTag(R.id.tag_click) as Long) >500){
            view.setTag(R.id.tag_click,currentTimeStamp)
            return true
        }
        return false
    }
}
